<script setup>
import {
    Management,
    Promotion,
    UserFilled,
    User,
    Crop,
    EditPen,
    SwitchButton,
    CaretBottom
} from '@element-plus/icons-vue'
import { ref } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { userInfoService } from '@/api/user.js'
import useUserInfoStore from '@/stores/userInfo.js'
import { useTokenStore } from '@/stores/token.js'
import { useRouter } from 'vue-router'
import avatar from '@/assets/default.png'

const tokenStore = useTokenStore()
const userInfoStore = useUserInfoStore()
const router = useRouter()

// 获取用户信息
const fetchUserInfo = async () => {
    try {
        const result = await userInfoService()
        userInfoStore.setInfo(result.data)
    } catch (error) {
        ElMessage.error(error.response?.data?.message || '获取用户信息失败')
    }
}

fetchUserInfo()

// 处理菜单命令
const handleCommand = (command) => {
    if (command === 'logout') {
        ElMessageBox.confirm(
            '您确认要退出吗?',
            '温馨提示',
            {
                confirmButtonText: '确认',
                cancelButtonText: '取消',
                type: 'warning',
            }
        )
        .then(async () => {
            tokenStore.removeToken()
            userInfoStore.removeInfo()
            router.push('/login')
            ElMessage.success('退出登录成功')
        })
        .catch(() => {
            ElMessage.info('用户取消了退出登录')
        })
    } else {
        router.push('/user/' + command)
    }
}
</script>

<template>
    <!-- 保持原有模板内容不变 -->
</template>

<style lang="scss" scoped>
/* 保持原有样式不变 */
</style>
